
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Kafka 如何解决数据丢失问题？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Kafka 如何解决数据丢失问题？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在Kafka的副本机制中，Leader副本和Follower副本各自扮演什么角色？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Leader副本（主副本）负责处理所有的读写请求。Follower副本（从副本）则从Leader副本拉取数据，以保持数据同步。</div>
          </div>
          <div class="card-source">来源: 1. 副本机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么是Kafka的ISR（In-Sync Replicas）机制，它如何保证数据的一致性和可靠性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">ISR是一个与Leader副本保持同步的副本列表。Kafka只允许从ISR中的副本读取数据，并且写入请求需要得到ISR中副本的确认后才算成功，从而确保数据的一致性和可靠性。</div>
          </div>
          <div class="card-source">来源: 2. ISR（In-Sync Replicas）机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">Kafka生产者配置中的`acks=all`（或`-1`）模式代表什么？它提供了何种级别的数据可靠性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">该模式意味着生产者会等待ISR（In-Sync Replicas）中所有副本的确认。这是最严格的确认模式，提供了最高的数据可靠性。</div>
          </div>
          <div class="card-source">来源: 4. 消息确认机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当一个分区的Leader副本发生故障时，Kafka的故障转移机制是如何工作的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当Leader副本发生故障时，Kafka会从ISR（In-Sync Replicas）列表中选举一个新的Leader副本，以继续处理数据请求，这保证了数据的可用性和可靠性。</div>
          </div>
          <div class="card-source">来源: 6. 故障转移</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Kafka中的`min.insync.replicas`配置项有什么作用？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">该配置项用于设定一个写入请求必须在至少多少个副本上得到确认才算成功。通过设置适当的值，可以防止在副本数量不足时写入请求被错误地认为成功，从而降低数据丢失的风险。</div>
          </div>
          <div class="card-source">来源: 7. 配置项</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Kafka的消费者偏移量（Consumer Offset）机制如何确保数据处理的可靠性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Kafka通过存储消费者的偏移量，使得消费者在发生故障后可以从上一次处理的位置继续消费数据。这避免了因消费者中断而导致的数据丢失或重复处理问题。</div>
          </div>
          <div class="card-source">来源: 5. 数据恢复和再处理</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Kafka是如何利用日志持久化来保证数据安全的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Kafka通过顺序写入的方式将数据追加到日志文件中，以最小化磁盘I/O开销。同时，它通过`log.retention.hours`和`log.retention.bytes`等配置项来控制日志的持久化策略，确保数据在日志文件中保存足够长的时间以防丢失。</div>
          </div>
          <div class="card-source">来源: 3. 日志持久化</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">请简述Kafka生产者`acks`参数的三种主要确认模式及其区别。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">1. `acks=0`：生产者不等待任何确认，性能最高但可靠性最低。<br>2. `acks=1`：生产者等待Leader副本的确认，是性能和可靠性的折中。<br>3. `acks=all` 或 `acks=-1`：生产者等待ISR中所有副本的确认，可靠性最高但性能开销最大。</div>
          </div>
          <div class="card-source">来源: 4. 消息确认机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当一个发生故障的副本恢复后，Kafka的自动恢复机制是如何运作的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">一旦故障副本恢复，它会重新加入ISR列表，并从新的Leader副本那里拉取其间缺失的数据。这种自动恢复机制保证了系统的高可用性和数据的一致性。</div>
          </div>
          <div class="card-source">来源: 6. 故障转移</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
